/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package FEMSolver;

import HashMatrix2.HashMatrix2;
import HashMatrix2.LUFactorization;
import java.awt.Toolkit;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;
import javax.swing.SwingWorker;

/**
 *
 * @author mark_o
 */
public class JustSolve extends SwingWorker<Void,Void>{
    protected double[] b;
    protected HashMatrix2 A;
    JProgressBar pb;
    JTextArea Text;
    public String outPath;

    protected ArrayList<Integer> NodeList;

    public JustSolve(double[] b, HashMatrix2 A, ArrayList<Integer> NodeList,JTextArea Text) {

        this.b = b;
        this.A = A;
        this.NodeList = NodeList;
        this.Text = Text;
    }

    @Override
    protected void done() {
        Toolkit.getDefaultToolkit().beep();
        Text.append("КІНЕЦЬ!!!");
        //pb.setIndeterminate(false);
    }



    @Override
    protected  Void doInBackground(){
        //pb.setIndeterminate(true);
        Text.append("\nПочаток LU-розкладу");
        LUFactorization lu = new LUFactorization(A);
        Text.append("\nКінець LU-розкладу");

        Text.append("\nПочаток процесу розвязування\n");
        try {
                Thread.sleep(100);
            } catch (InterruptedException ignore) {}
        double[] u1 = lu.calculate(b);
            Text.setCaretPosition(Text.getText().length());
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignore) {}

        PrintWriter pw =  null;
        try {
            try {
                pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(outPath)));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(JustSolve.class.getName()).log(Level.SEVERE, null, ex);
            }
            pw.println(u1.length);
            for(int i=0;i<u1.length;i++){
                pw.println(u1[i]);
            }
        }finally{
            pw.close();
        }


        return null;
    }
}
